package com.dnjn.happiness.biz.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dnjn.happiness.biz.domain.OutletReply;
import com.dnjn.happiness.biz.domain.vo.OutletReplyVO;
import com.dnjn.happiness.biz.service.IOutletReplyService;
import com.dnjn.happiness.common.cloud.controller.BaseController;
import com.dnjn.happiness.common.core.utils.bean.BeanUtils;
import com.dnjn.happiness.common.core.web.domain.AjaxResult;
import com.dnjn.happiness.common.log.annotation.Log;
import com.dnjn.happiness.common.log.enums.BusinessType;
import com.dnjn.happiness.common.security.utils.SecurityUtils;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * 解忧馆回复记录Controller
 *
 * @author happiness
 * @date 2024-03-14
 */
@Tag(name = "biz reply 解忧馆回复记录", description = "解忧馆回复记录")
@RestController
@RequestMapping("/reply")
public class OutletReplyController extends BaseController {
    @Autowired
    private IOutletReplyService outletReplyService;

    /**
     * 查询解忧馆回复记录列表
     */
    //@RequiresPermissions("@ss.hasPermi('biz:reply:list')")
    @PostMapping("/list")
    @Log(title = "biz", businessType = BusinessType.LIST)
    public AjaxResult list(@RequestBody OutletReplyVO vo, @RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size) {
        OutletReply outletReply = new OutletReply();
        BeanUtils.copyPropsIgnoreNull(vo, outletReply);
        Page page = Page.of(current, size);
        Page<OutletReply> list = outletReplyService.page(page, Wrappers.query(outletReply));
        return success(list);
    }

    /**
     * 获取解忧馆回复记录详细信息
     */
    //@RequiresPermissions("@ss.hasPermi('biz:reply:query')")
    @GetMapping(value = "/{outletId}")
    @Log(title = "biz", businessType = BusinessType.SELECT)
    public AjaxResult get(@PathVariable("outletId") Long outletId) {
        return success(outletReplyService.getById(outletId));
    }

    /**
     * 新增解忧馆回复记录
     */
    @Log(title = "解忧馆回复记录", businessType = BusinessType.INSERT)
    //@RequiresPermissions("@ss.hasPermi('biz:reply:add')")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody OutletReplyVO vo) {
        OutletReply outletReply = new OutletReply();
        BeanUtils.copyPropsIgnoreNull(vo, outletReply);

        outletReply.setCreateBy(SecurityUtils.getUsername());
        return toAjax(outletReplyService.save(outletReply));
    }

    /**
     * 修改解忧馆回复记录
     */
    @Log(title = "解忧馆回复记录", businessType = BusinessType.UPDATE)
    //@RequiresPermissions("@ss.hasPermi('biz:reply:edit')")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody OutletReplyVO vo) {
        OutletReply outletReply = new OutletReply();
        BeanUtils.copyPropsIgnoreNull(vo, outletReply);
        return toAjax(outletReplyService.updateById(outletReply));
    }

    /**
     * 删除解忧馆回复记录
     */
    @Log(title = "解忧馆回复记录", businessType = BusinessType.DELETE)
    //@RequiresPermissions("@ss.hasPermi('biz:reply:remove')")
    @DeleteMapping("/{outletIds}")
    public AjaxResult remove(@PathVariable Long[] outletIds) {
        return toAjax(outletReplyService.removeBatchByIds(Arrays.asList(outletIds)));
    }
}
